package com.summer.authentication.controller;


import com.summer.authentication.mapper.XcUserMapper;
import com.summer.authentication.pojo.XcUser;
import com.summer.authentication.service.VxLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@Slf4j
public class VxLogin {

    @Autowired
    private XcUserMapper userMapper;

    @Autowired
    private VxLoginService vxLoginService;

    /**
     * 微信扫码授权后的回调地址（redirect_url）, 注意此时是重定向而不是返回rest风格数据
     *
     * @param code  授权码
     * @param state state
     * @return 重定向到自动登录页或错误页
     */
    @RequestMapping("login_vx")
    @ResponseBody
    public String wxLogin(String code, String state) {
        log.info("微信回调参数：code={}, state={}", code, state);
        return vxLoginService.vxLogin(code);
    }

}
